### CODE FOR:
###
### Partisan Influence on Policy Preferences 
### When Parties and Voters Disagree on Welfare Retrenchment
###
### PART 2-1: Descriptive (policy) preference changes
###           for government voters (Figure 2)
###
### VERSION: 2024-MAR-01


rm(list=ls())
gc()



# WORKING DIRECTORY -------------------------------------------------------
setwd("C:/Users/miros/Desktop/Research/Finland - Partisan Cues in Citizens Attitudes")



# LIBRARIES ---------------------------------------------------------------
library(tidyverse)
library(ggplot2)
library(RColorBrewer)
library(grid)
library(ggpubr)
library(patchwork)
library(ggalluvial)
library(scales)



# DATA IMPORT -------------------------------------------------------------
# NOTE: The data file loaded in the next step was prepared in a separate
#       scripts '01_PartyCues-data_prep.R'. If you haven't run the script, 
#       return to the depository and run that script first. Its output is 
#       'BIBU_long.Rda' loaded in the next step.
load("01-data/BIBU_long.Rda")




# DATA PREPARATION --------------------------------------------------------

# Policy preferences into binary variables
BIBU.DiD <-
  BIBU.DiD %>%
  mutate(RETIREMENT_TUBE_BI = as.factor(
    ifelse((RETIREMENT_TUBE == 1 | RETIREMENT_TUBE == 2), "Strongly/Somewhat disagree",
           ifelse((RETIREMENT_TUBE == 3 | RETIREMENT_TUBE == 4), "Strongly/Somewhat agree",
                  NA)))) %>%
  
  mutate(COMPULSORY_SCHOOLING_BI = as.factor(
    ifelse((COMPULSORY_SCHOOLING == 1 | COMPULSORY_SCHOOLING == 2), "Strongly/Somewhat disagree",
           ifelse((COMPULSORY_SCHOOLING == 3 | COMPULSORY_SCHOOLING == 4), "Strongly/Somewhat agree",
                  NA))))




# FIGURE 2 ----------------------------------------------------------------

# _ Social Democrats ------------------------------------------------------

# __ Data preparation -----------------------------------------------------
BIBU.SocDem <-
  BIBU.DiD %>%
  select(MEMBERID, ROUND, RETIREMENT_TUBE_BI, PartyChoice.Overall) %>%
  filter(PartyChoice.Overall == "Social Democrats") %>%
  na.omit() %>%
  group_by(MEMBERID) %>%
  mutate(count = n()) %>%
  filter(count == 2) %>%
  select(-count)

BIBU.SocDem <-
  BIBU.DiD %>%
  select(MEMBERID, ROUND, COMPULSORY_SCHOOLING_BI, PartyChoice.Overall) %>%
  filter(PartyChoice.Overall == "Social Democrats") %>%
  na.omit() %>%
  group_by(MEMBERID) %>%
  mutate(count = n()) %>%
  filter(count == 2) %>%
  select(-c(count, PartyChoice.Overall)) %>%
  full_join(., BIBU.SocDem, by = c("MEMBERID", "ROUND"))

BIBU.SocDem <-
  BIBU.DiD %>%
  select(MEMBERID, ROUND, LeftRight, PartyChoice.Overall) %>%
  filter(PartyChoice.Overall == "Social Democrats") %>%
  na.omit() %>%
  group_by(MEMBERID) %>%
  mutate(count = n()) %>%
  filter(count == 2) %>%
  select(-c(count, PartyChoice.Overall)) %>%
  full_join(., BIBU.SocDem, by = c("MEMBERID", "ROUND"))

BIBU.SocDem$PartyChoice.Overall <- "Social Democrats"



# __ Figure ---------------------------------------------------------------

SocialDemocrats <-
  ggarrange(
    # Kernel density plot
    ggplot(filter(BIBU.SocDem, !is.na(LeftRight) & ROUND == "Round 1"), 
           aes(x = LeftRight)) +
      geom_density(alpha = 0.65, 
                   bw = 0.75, 
                   color = brewer.pal(n = 9, name = "Greys")[5],
                   fill = brewer.pal(n = 9, name = "Greys")[3]) +
      geom_segment(x = mean(BIBU.SocDem$LeftRight), 
                   xend = mean(BIBU.SocDem$LeftRight), 
                   y = 0, 
                   yend = 0.265, 
                   color = brewer.pal(n = 9, name = "Greys")[7], 
                   linetype = "longdash") +
      scale_x_continuous(breaks = seq(0, 10, 1), labels = c("0", "\nLeft", "", "", "", "5", "", "", "", "\nRight", "10")) +
      scale_y_continuous(breaks = seq(0, 0.5, 0.05), labels = c("0.0", "", "0.1", "", "0.2", "", "0.3", "", "0.4", "", "0.5")) +
      labs(title = NULL, x = NULL, y = NULL, fill = NULL, color = NULL) +
      geom_rect(ymin = 0.5 * 1.05, ymax = 0.5 * 1.25, xmin = 0 - 0.33, xmax = 10 + 0.33, colour = "black", fill = "grey90") +
      annotate("text", x = 5, y = 0.5 * 1.14, hjust = 0.5, vjust = -0.2, label = "Left-right distribution", fontface = 2, size = 13/.pt) +
      annotate("text", x = 5, y = 0.5 * 1.14, hjust = 0.5, vjust = 1.2, label = "as measured in Round 1", size = 10/.pt) +
      coord_cartesian(xlim = c(0 - 0.33, 10 + 0.33), ylim = c(0, 0.5 * 1.25), expand = FALSE, clip = "off") +
      theme(text = element_text(size = 12, color = "black"),
            axis.text.x = element_blank(),
            panel.grid.major.x = element_blank(), 
            panel.grid.major.y = element_line(colour = "gray90"), 
            panel.grid.minor.y = element_blank(), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent"),
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.35, 0.2, 0.05, 0.05),"cm")),
    
    
    # Welfare retrenchment
    ggplot(filter(BIBU.SocDem, !is.na(RETIREMENT_TUBE_BI)), 
           aes(x = ROUND, 
               stratum = RETIREMENT_TUBE_BI, 
               fill = as.factor(RETIREMENT_TUBE_BI), 
               alluvium = MEMBERID)) +
      scale_fill_manual(values = brewer.pal(n = 9, name = "Greys")[c(6, 4)]) +
      geom_flow(width = 0.75) +
      geom_stratum(alpha = 0.5, width = 0.75) + 
      geom_text(stat = "stratum", color = "black", aes(label = percent(after_stat(prop), accuracy = .1)), size = 11/.pt, vjust = -0.1) +
      geom_text(stat = "stratum", color = "black", aes(label = paste0("(N=",after_stat(count),")")), size = 8.5/.pt, vjust = 1.1) +
      scale_x_discrete(limits = c("Round 1", "Round 2"), labels = c("Before\nthe reform", "After\nthe reform")) +
      labs(title = NULL, x = NULL, y = NULL) +
      coord_cartesian(xlim = c(0.6, 2.4), 
                      ylim = c(-(nrow(filter(BIBU.SocDem, !is.na(RETIREMENT_TUBE_BI)))/2)*0.01, 
                               (nrow(filter(BIBU.SocDem, !is.na(RETIREMENT_TUBE_BI)))/2)*1.25), 
                      expand = FALSE, 
                      clip = "off") +
      scale_y_continuous(breaks = seq(from = 0, 
                                      to = nrow(filter(BIBU.SocDem, !is.na(RETIREMENT_TUBE_BI)))/2, 
                                      by = nrow(filter(BIBU.SocDem, !is.na(RETIREMENT_TUBE_BI)))/10),
                         labels = c("0%", "20%", "40%", "60%", "80%", "100%")) +
      geom_rect(ymin = (nrow(filter(BIBU.SocDem, !is.na(RETIREMENT_TUBE_BI)))/2)*1.05, 
                ymax = (nrow(filter(BIBU.SocDem, !is.na(RETIREMENT_TUBE_BI)))/2)*1.25, 
                xmin = 0.6, 
                xmax = 2.4, 
                colour = "black", 
                fill = "grey90") +
      annotate("text", x = 1.5, y = (nrow(filter(BIBU.SocDem, !is.na(RETIREMENT_TUBE_BI)))/2)*1.14, hjust = 0.5, vjust = -0.2, label = "Welfare retrenchment", fontface = 2, size = 13/.pt) +
      annotate("text", x = 1.5, y = (nrow(filter(BIBU.SocDem, !is.na(RETIREMENT_TUBE_BI)))/2)*1.14, hjust = 0.5, vjust =  1.2, label = "Abolition of the 'retirement tube'", size = 10/.pt) +
      theme(text = element_text(size = 12, color = "black"),
            axis.text.x = element_blank(),
            panel.grid.major.x = element_blank(),
            panel.grid.minor.x = element_blank(), 
            panel.grid.major.y = element_line(color = "grey90"),
            panel.grid.minor.y = element_line(color = "grey90"), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent", color = "transparent"),
            legend.position = "none", 
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.35, 0.05, 0.15, 0.05),"cm")),
    
    
    # Welfare expansion
    ggplot(filter(BIBU.SocDem, !is.na(COMPULSORY_SCHOOLING_BI)), 
           aes(x = ROUND, 
               stratum = COMPULSORY_SCHOOLING_BI, 
               fill = as.factor(COMPULSORY_SCHOOLING_BI), 
               alluvium = MEMBERID)) +
      scale_fill_manual(values = brewer.pal(n = 9, name = "Greys")[c(6, 4)]) +
      geom_flow(width = 0.75) +
      geom_stratum(alpha = 0.5, width = 0.75) + 
      geom_text(stat = "stratum", color = "black", aes(label = percent(after_stat(prop), accuracy = .1)), size = 11/.pt, vjust = -0.1) +
      geom_text(stat = "stratum", color = "black", aes(label = paste0("(N=",after_stat(count),")")), size = 8.5/.pt, vjust = 1.1) +
      scale_x_discrete(limits = c("Round 1", "Round 2"), labels = c("Before\nthe reform", "After\nthe reform")) +
      labs(title = NULL, x = NULL, y = NULL) +
      coord_cartesian(xlim = c(0.6, 2.6), 
                      ylim = c(-(nrow(filter(BIBU.SocDem, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*0.01, 
                               (nrow(filter(BIBU.SocDem, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*1.25), 
                      expand = FALSE, 
                      clip = "off") +
      scale_y_continuous(breaks = seq(from = 0, 
                                      to = nrow(filter(BIBU.SocDem, !is.na(COMPULSORY_SCHOOLING_BI)))/2, 
                                      by = nrow(filter(BIBU.SocDem, !is.na(COMPULSORY_SCHOOLING_BI)))/10),
                         labels = c("0%", "20%", "40%", "60%", "80%", "100%")) +
      geom_rect(ymin = (nrow(filter(BIBU.SocDem, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*1.05, 
                ymax = (nrow(filter(BIBU.SocDem, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*1.25, 
                xmin = 0.6, 
                xmax = 2.4, 
                colour = "black", 
                fill = "grey90") +
      annotate("text", x = 1.5, y = (nrow(filter(BIBU.SocDem, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*1.14, hjust = 0.5, vjust = -0.2, label = "Welfare expansion", fontface = 2, size = 13/.pt) +
      annotate("text", x = 1.5, y = (nrow(filter(BIBU.SocDem, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*1.14, hjust = 0.5, vjust =  1.2, label = "Extension of the compulsory school age", size = 10/.pt) +
      geom_rect(ymin = -(nrow(filter(BIBU.SocDem, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*0.01, 
                ymax =  (nrow(filter(BIBU.SocDem, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*1.01, 
                xmin = 2.4, 
                xmax = 2.6, 
                colour = "black", 
                fill = "grey90") +
      annotate("text", x = 2.5, y = (nrow(filter(BIBU.SocDem, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*0.5, hjust = 0.5, vjust = 0.5, label = "Social Democrats", angle = 270, fontface = 2, size = 13/.pt) +
      theme(text = element_text(size = 12, color = "black"),
            axis.text.x = element_blank(),
            panel.grid.major.x = element_blank(),
            panel.grid.minor.x = element_blank(), 
            panel.grid.major.y = element_line(color = "grey90"),
            panel.grid.minor.y = element_line(color = "grey90"), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent", color = "transparent"),
            legend.position = "none", 
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.35, 0.05, 0.15, 0.05),"cm")),
    
    # General specs
    ncol = 3, widths = c(3, 4, 4.25),
    align = "hv")




# _ Left Alliance ---------------------------------------------------------

# __ Data preparation -----------------------------------------------------
BIBU.LeftA <-
  BIBU.DiD %>%
  select(MEMBERID, ROUND, RETIREMENT_TUBE_BI, PartyChoice.Overall) %>%
  filter(PartyChoice.Overall == "Left Alliance") %>%
  na.omit() %>%
  group_by(MEMBERID) %>%
  mutate(count = n()) %>%
  filter(count == 2) %>%
  select(-count)

BIBU.LeftA <-
  BIBU.DiD %>%
  select(MEMBERID, ROUND, COMPULSORY_SCHOOLING_BI, PartyChoice.Overall) %>%
  filter(PartyChoice.Overall == "Left Alliance") %>%
  na.omit() %>%
  group_by(MEMBERID) %>%
  mutate(count = n()) %>%
  filter(count == 2) %>%
  select(-c(count, PartyChoice.Overall)) %>%
  full_join(., BIBU.LeftA, by = c("MEMBERID", "ROUND"))

BIBU.LeftA <-
  BIBU.DiD %>%
  select(MEMBERID, ROUND, LeftRight, PartyChoice.Overall) %>%
  filter(PartyChoice.Overall == "Left Alliance") %>%
  na.omit() %>%
  group_by(MEMBERID) %>%
  mutate(count = n()) %>%
  filter(count == 2) %>%
  select(-c(count, PartyChoice.Overall)) %>%
  full_join(., BIBU.LeftA, by = c("MEMBERID", "ROUND"))

BIBU.LeftA$PartyChoice.Overall <- "Left Alliance"



# __ Figure ---------------------------------------------------------------

LeftAlliance <-
  ggarrange(
    # Kernel density plot
    ggplot(filter(BIBU.LeftA, !is.na(LeftRight) & ROUND == "Round 1"), 
           aes(x = LeftRight)) +
      geom_density(alpha = 0.65, 
                   bw = 0.75, 
                   color = brewer.pal(n = 9, name = "Greys")[5],
                   fill = brewer.pal(n = 9, name = "Greys")[3]) +
      geom_segment(x = mean(BIBU.LeftA$LeftRight), 
                   xend = mean(BIBU.LeftA$LeftRight), 
                   y = 0, 
                   yend = 0.242, 
                   color = brewer.pal(n = 9, name = "Greys")[7], 
                   linetype = "longdash") +
      scale_x_continuous(breaks = seq(0, 10, 1), labels = c("0", "\nLeft", "", "", "", "5", "", "", "", "\nRight", "10")) +
      scale_y_continuous(breaks = seq(0, 0.5, 0.05), labels = c("0.0", "", "0.1", "", "0.2", "", "0.3", "", "0.4", "", "0.5")) +
      labs(title = NULL, x = NULL, y = NULL, fill = NULL, color = NULL) +
      coord_cartesian(xlim = c(0 - 0.33, 10 + 0.33), ylim = c(0, 0.5 * 1.01), expand = FALSE, clip = "off") +
      theme(text = element_text(size = 12, color = "black"),
            axis.text.x = element_blank(),
            panel.grid.major.x = element_blank(), 
            panel.grid.major.y = element_line(colour = "gray90"), 
            panel.grid.minor.y = element_blank(), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent"),
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.05, 0.2, 0.05, 0.05),"cm")),
    
    
    # Welfare retrenchment
    ggplot(filter(BIBU.LeftA, !is.na(RETIREMENT_TUBE_BI)), 
           aes(x = ROUND, 
               stratum = RETIREMENT_TUBE_BI, 
               fill = as.factor(RETIREMENT_TUBE_BI), 
               alluvium = MEMBERID)) +
      scale_fill_manual(values = brewer.pal(n = 9, name = "Greys")[c(6, 4)]) +
      geom_flow(width = 0.75) +
      geom_stratum(alpha = 0.5, width = 0.75) + 
      geom_text(stat = "stratum", color = "black", aes(label = percent(after_stat(prop), accuracy = .1)), size = 11/.pt, vjust = -0.1) +
      geom_text(stat = "stratum", color = "black", aes(label = paste0("(N=",after_stat(count),")")), size = 8.5/.pt, vjust = 1.1) +
      scale_x_discrete(limits = c("Round 1", "Round 2"), labels = c("Before\nthe reform", "After\nthe reform")) +
      labs(title = NULL, x = NULL, y = NULL) +
      coord_cartesian(xlim = c(0.6, 2.4), 
                      ylim = c(-(nrow(filter(BIBU.LeftA, !is.na(RETIREMENT_TUBE_BI)))/2)*0.01, 
                               (nrow(filter(BIBU.LeftA, !is.na(RETIREMENT_TUBE_BI)))/2)*1.01), 
                      expand = FALSE, 
                      clip = "off") +
      scale_y_continuous(breaks = seq(from = 0, 
                                      to = nrow(filter(BIBU.LeftA, !is.na(RETIREMENT_TUBE_BI)))/2, 
                                      by = nrow(filter(BIBU.LeftA, !is.na(RETIREMENT_TUBE_BI)))/10),
                         labels = c("0%", "20%", "40%", "60%", "80%", "100%")) +
      theme(text = element_text(size = 12, color = "black"),
            axis.text.x = element_blank(),
            panel.grid.major.x = element_blank(),
            panel.grid.minor.x = element_blank(), 
            panel.grid.major.y = element_line(color = "grey90"),
            panel.grid.minor.y = element_line(color = "grey90"), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent", color = "transparent"),
            legend.position = "none", 
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.15, 0.05, 0.15, 0.05),"cm")),
    
    
    # Welfare expansion
    ggplot(filter(BIBU.LeftA, !is.na(COMPULSORY_SCHOOLING_BI)), 
           aes(x = ROUND, 
               stratum = COMPULSORY_SCHOOLING_BI, 
               fill = as.factor(COMPULSORY_SCHOOLING_BI), 
               alluvium = MEMBERID)) +
      scale_fill_manual(values = brewer.pal(n = 9, name = "Greys")[c(6, 4)]) +
      geom_flow(width = 0.75) +
      geom_stratum(alpha = 0.5, width = 0.75) + 
      geom_text(stat = "stratum", color = "black", aes(label = percent(after_stat(prop), accuracy = .1)), size = 11/.pt, vjust = -0.1) +
      geom_text(stat = "stratum", color = "black", aes(label = paste0("(N=",after_stat(count),")")), size = 8.5/.pt, vjust = 1.1) +
      scale_x_discrete(limits = c("Round 1", "Round 2"), labels = c("Before\nthe reform", "After\nthe reform")) +
      labs(title = NULL, x = NULL, y = NULL) +
      coord_cartesian(xlim = c(0.6, 2.6), 
                      ylim = c(-(nrow(filter(BIBU.LeftA, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*0.01, 
                               (nrow(filter(BIBU.LeftA, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*1.01), 
                      expand = FALSE, 
                      clip = "off") +
      scale_y_continuous(breaks = seq(from = 0, 
                                      to = nrow(filter(BIBU.LeftA, !is.na(COMPULSORY_SCHOOLING_BI)))/2, 
                                      by = nrow(filter(BIBU.LeftA, !is.na(COMPULSORY_SCHOOLING_BI)))/10),
                         labels = c("0%", "20%", "40%", "60%", "80%", "100%")) +
      geom_rect(ymin = -(nrow(filter(BIBU.LeftA, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*0.01, 
                ymax =  (nrow(filter(BIBU.LeftA, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*1.01, 
                xmin = 2.4, 
                xmax = 2.6, 
                colour = "black", 
                fill = "grey90") +
      annotate("text", x = 2.5, y = (nrow(filter(BIBU.LeftA, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*0.5, hjust = 0.5, vjust = 0.5, label = "Left Alliance", angle = 270, fontface = 2, size = 13/.pt) +
      theme(text = element_text(size = 12, color = "black"),
            axis.text.x = element_blank(),
            panel.grid.major.x = element_blank(),
            panel.grid.minor.x = element_blank(), 
            panel.grid.major.y = element_line(color = "grey90"),
            panel.grid.minor.y = element_line(color = "grey90"), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent", color = "transparent"),
            legend.position = "none", 
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.15, 0.05, 0.15, 0.05),"cm")),
    
    # General specs
    ncol = 3, widths = c(3, 4, 4.25),
    align = "hv")





# _ Greens ----------------------------------------------------------------

# __ Data preparation -----------------------------------------------------
BIBU.Greens <-
  BIBU.DiD %>%
  select(MEMBERID, ROUND, RETIREMENT_TUBE_BI, PartyChoice.Overall) %>%
  filter(PartyChoice.Overall == "Greens") %>%
  na.omit() %>%
  group_by(MEMBERID) %>%
  mutate(count = n()) %>%
  filter(count == 2) %>%
  select(-count)

BIBU.Greens <-
  BIBU.DiD %>%
  select(MEMBERID, ROUND, COMPULSORY_SCHOOLING_BI, PartyChoice.Overall) %>%
  filter(PartyChoice.Overall == "Greens") %>%
  na.omit() %>%
  group_by(MEMBERID) %>%
  mutate(count = n()) %>%
  filter(count == 2) %>%
  select(-c(count, PartyChoice.Overall)) %>%
  full_join(., BIBU.Greens, by = c("MEMBERID", "ROUND"))

BIBU.Greens <-
  BIBU.DiD %>%
  select(MEMBERID, ROUND, LeftRight, PartyChoice.Overall) %>%
  filter(PartyChoice.Overall == "Greens") %>%
  na.omit() %>%
  group_by(MEMBERID) %>%
  mutate(count = n()) %>%
  filter(count == 2) %>%
  select(-c(count, PartyChoice.Overall)) %>%
  full_join(., BIBU.Greens, by = c("MEMBERID", "ROUND"))

BIBU.Greens$PartyChoice.Overall <- "Greens"



# __ Figure ---------------------------------------------------------------

Greens <-
  ggarrange(
    # Kernel density plot
    ggplot(filter(BIBU.Greens, !is.na(LeftRight) & ROUND == "Round 1"), 
           aes(x = LeftRight)) +
      geom_density(alpha = 0.65, 
                   bw = 0.75, 
                   color = brewer.pal(n = 9, name = "Greys")[5],
                   fill = brewer.pal(n = 9, name = "Greys")[3]) +
      geom_segment(x = mean(BIBU.Greens$LeftRight), 
                   xend = mean(BIBU.Greens$LeftRight), 
                   y = 0, 
                   yend = 0.212, 
                   color = brewer.pal(n = 9, name = "Greys")[7], 
                   linetype = "longdash") +
      scale_x_continuous(breaks = seq(0, 10, 1), labels = c("0", "\nLeft", "", "", "", "5", "", "", "", "\nRight", "10")) +
      scale_y_continuous(breaks = seq(0, 0.5, 0.05), labels = c("0.0", "", "0.1", "", "0.2", "", "0.3", "", "0.4", "", "0.5")) +
      labs(title = NULL, x = NULL, y = NULL, fill = NULL, color = NULL) +
      coord_cartesian(xlim = c(0 - 0.33, 10 + 0.33), ylim = c(0, 0.5 * 1.01), expand = FALSE, clip = "off") +
      theme(text = element_text(size = 12, color = "black"),
            axis.text.x = element_blank(),
            panel.grid.major.x = element_blank(), 
            panel.grid.major.y = element_line(colour = "gray90"), 
            panel.grid.minor.y = element_blank(), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent"),
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.05, 0.2, 0.05, 0.05),"cm")),
    
    
    # Welfare retrenchment
    ggplot(filter(BIBU.Greens, !is.na(RETIREMENT_TUBE_BI)), 
           aes(x = ROUND, 
               stratum = RETIREMENT_TUBE_BI, 
               fill = as.factor(RETIREMENT_TUBE_BI), 
               alluvium = MEMBERID)) +
      scale_fill_manual(values = brewer.pal(n = 9, name = "Greys")[c(6, 4)]) +
      geom_flow(width = 0.75) +
      geom_stratum(alpha = 0.5, width = 0.75) + 
      geom_text(stat = "stratum", color = "black", aes(label = percent(after_stat(prop), accuracy = .1)), size = 11/.pt, vjust = -0.1) +
      geom_text(stat = "stratum", color = "black", aes(label = paste0("(N=",after_stat(count),")")), size = 8.5/.pt, vjust = 1.1) +
      scale_x_discrete(limits = c("Round 1", "Round 2"), labels = c("Before\nthe reform", "After\nthe reform")) +
      labs(title = NULL, x = NULL, y = NULL) +
      coord_cartesian(xlim = c(0.6, 2.4), 
                      ylim = c(-(nrow(filter(BIBU.Greens, !is.na(RETIREMENT_TUBE_BI)))/2)*0.01, 
                               (nrow(filter(BIBU.Greens, !is.na(RETIREMENT_TUBE_BI)))/2)*1.01), 
                      expand = FALSE, 
                      clip = "off") +
      scale_y_continuous(breaks = seq(from = 0, 
                                      to = nrow(filter(BIBU.Greens, !is.na(RETIREMENT_TUBE_BI)))/2, 
                                      by = nrow(filter(BIBU.Greens, !is.na(RETIREMENT_TUBE_BI)))/10),
                         labels = c("0%", "20%", "40%", "60%", "80%", "100%")) +
      theme(text = element_text(size = 12, color = "black"),
            axis.text.x = element_blank(),
            panel.grid.major.x = element_blank(),
            panel.grid.minor.x = element_blank(), 
            panel.grid.major.y = element_line(color = "grey90"),
            panel.grid.minor.y = element_line(color = "grey90"), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent", color = "transparent"),
            legend.position = "none", 
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.15, 0.05, 0.15, 0.05),"cm")),
    
    
    # Welfare expansion
    ggplot(filter(BIBU.Greens, !is.na(COMPULSORY_SCHOOLING_BI)), 
           aes(x = ROUND, 
               stratum = COMPULSORY_SCHOOLING_BI, 
               fill = as.factor(COMPULSORY_SCHOOLING_BI), 
               alluvium = MEMBERID)) +
      scale_fill_manual(values = brewer.pal(n = 9, name = "Greys")[c(6, 4)]) +
      geom_flow(width = 0.75) +
      geom_stratum(alpha = 0.5, width = 0.75) + 
      geom_text(stat = "stratum", color = "black", aes(label = percent(after_stat(prop), accuracy = .1)), size = 11/.pt, vjust = -0.1) +
      geom_text(stat = "stratum", color = "black", aes(label = paste0("(N=",after_stat(count),")")), size = 8.5/.pt, vjust = 1.1) +
      scale_x_discrete(limits = c("Round 1", "Round 2"), labels = c("Before\nthe reform", "After\nthe reform")) +
      labs(title = NULL, x = NULL, y = NULL) +
      coord_cartesian(xlim = c(0.6, 2.6), 
                      ylim = c(-(nrow(filter(BIBU.Greens, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*0.01, 
                               (nrow(filter(BIBU.Greens, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*1.01), 
                      expand = FALSE, 
                      clip = "off") +
      scale_y_continuous(breaks = seq(from = 0, 
                                      to = nrow(filter(BIBU.Greens, !is.na(COMPULSORY_SCHOOLING_BI)))/2, 
                                      by = nrow(filter(BIBU.Greens, !is.na(COMPULSORY_SCHOOLING_BI)))/10),
                         labels = c("0%", "20%", "40%", "60%", "80%", "100%")) +
      geom_rect(ymin = -(nrow(filter(BIBU.Greens, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*0.01, 
                ymax =  (nrow(filter(BIBU.Greens, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*1.01, 
                xmin = 2.4, 
                xmax = 2.6, 
                colour = "black", 
                fill = "grey90") +
      annotate("text", x = 2.5, y = (nrow(filter(BIBU.Greens, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*0.5, hjust = 0.5, vjust = 0.5, label = "Greens", angle = 270, fontface = 2, size = 13/.pt) +
      theme(text = element_text(size = 12, color = "black"),
            axis.text.x = element_blank(),
            panel.grid.major.x = element_blank(),
            panel.grid.minor.x = element_blank(), 
            panel.grid.major.y = element_line(color = "grey90"),
            panel.grid.minor.y = element_line(color = "grey90"), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent", color = "transparent"),
            legend.position = "none", 
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.15, 0.05, 0.15, 0.05),"cm")),
    
    # General specs
    ncol = 3, widths = c(3, 4, 4.25),
    align = "hv")





# _ Centre Party ----------------------------------------------------------

# __ Data preparation -----------------------------------------------------
BIBU.Centre <-
  BIBU.DiD %>%
  select(MEMBERID, ROUND, RETIREMENT_TUBE_BI, PartyChoice.Overall) %>%
  filter(PartyChoice.Overall == "Centre Party") %>%
  na.omit() %>%
  group_by(MEMBERID) %>%
  mutate(count = n()) %>%
  filter(count == 2) %>%
  select(-count)

BIBU.Centre <-
  BIBU.DiD %>%
  select(MEMBERID, ROUND, COMPULSORY_SCHOOLING_BI, PartyChoice.Overall) %>%
  filter(PartyChoice.Overall == "Centre Party") %>%
  na.omit() %>%
  group_by(MEMBERID) %>%
  mutate(count = n()) %>%
  filter(count == 2) %>%
  select(-c(count, PartyChoice.Overall)) %>%
  full_join(., BIBU.Centre, by = c("MEMBERID", "ROUND"))

BIBU.Centre <-
  BIBU.DiD %>%
  select(MEMBERID, ROUND, LeftRight, PartyChoice.Overall) %>%
  filter(PartyChoice.Overall == "Centre Party") %>%
  na.omit() %>%
  group_by(MEMBERID) %>%
  mutate(count = n()) %>%
  filter(count == 2) %>%
  select(-c(count, PartyChoice.Overall)) %>%
  full_join(., BIBU.Centre, by = c("MEMBERID", "ROUND"))

BIBU.Centre$PartyChoice.Overall <- "Centre Party"



# __ Figure ---------------------------------------------------------------

Centre <-
  ggarrange(
    # Kernel density plot
    ggplot(filter(BIBU.Centre, !is.na(LeftRight) & ROUND == "Round 1"), 
           aes(x = LeftRight)) +
      geom_density(alpha = 0.65, 
                   bw = 0.75, 
                   color = brewer.pal(n = 9, name = "Greys")[5],
                   fill = brewer.pal(n = 9, name = "Greys")[3]) +
      geom_segment(x = mean(BIBU.Centre$LeftRight), 
                   xend = mean(BIBU.Centre$LeftRight), 
                   y = 0, 
                   yend = 0.230, 
                   color = brewer.pal(n = 9, name = "Greys")[7], 
                   linetype = "longdash") +
      scale_x_continuous(breaks = seq(0, 10, 1), labels = c("0", "\nLeft", "", "", "", "5", "", "", "", "\nRight", "10")) +
      scale_y_continuous(breaks = seq(0, 0.5, 0.05), labels = c("0.0", "", "0.1", "", "0.2", "", "0.3", "", "0.4", "", "0.5")) +
      labs(title = NULL, x = NULL, y = NULL, fill = NULL, color = NULL) +
      coord_cartesian(xlim = c(0 - 0.33, 10 + 0.33), ylim = c(0, 0.5 * 1.01), expand = FALSE, clip = "off") +
      theme(text = element_text(size = 12, color = "black"),
            axis.text.x = element_blank(),
            panel.grid.major.x = element_blank(), 
            panel.grid.major.y = element_line(colour = "gray90"), 
            panel.grid.minor.y = element_blank(), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent"),
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.05, 0.2, 0.05, 0.05),"cm")),
    
    
    # Welfare retrenchment
    ggplot(filter(BIBU.Centre, !is.na(RETIREMENT_TUBE_BI)), 
           aes(x = ROUND, 
               stratum = RETIREMENT_TUBE_BI, 
               fill = as.factor(RETIREMENT_TUBE_BI), 
               alluvium = MEMBERID)) +
      scale_fill_manual(values = brewer.pal(n = 9, name = "Greys")[c(6, 4)]) +
      geom_flow(width = 0.75) +
      geom_stratum(alpha = 0.5, width = 0.75) + 
      geom_text(stat = "stratum", color = "black", aes(label = percent(after_stat(prop), accuracy = .1)), size = 11/.pt, vjust = -0.1) +
      geom_text(stat = "stratum", color = "black", aes(label = paste0("(N=",after_stat(count),")")), size = 8.5/.pt, vjust = 1.1) +
      scale_x_discrete(limits = c("Round 1", "Round 2"), labels = c("Before\nthe reform", "After\nthe reform")) +
      labs(title = NULL, x = NULL, y = NULL) +
      coord_cartesian(xlim = c(0.6, 2.4), 
                      ylim = c(-(nrow(filter(BIBU.Centre, !is.na(RETIREMENT_TUBE_BI)))/2)*0.01, 
                               (nrow(filter(BIBU.Centre, !is.na(RETIREMENT_TUBE_BI)))/2)*1.01), 
                      expand = FALSE, 
                      clip = "off") +
      scale_y_continuous(breaks = seq(from = 0, 
                                      to = nrow(filter(BIBU.Centre, !is.na(RETIREMENT_TUBE_BI)))/2, 
                                      by = nrow(filter(BIBU.Centre, !is.na(RETIREMENT_TUBE_BI)))/10),
                         labels = c("0%", "20%", "40%", "60%", "80%", "100%")) +
      theme(text = element_text(size = 12, color = "black"),
            axis.text.x = element_blank(),
            panel.grid.major.x = element_blank(),
            panel.grid.minor.x = element_blank(), 
            panel.grid.major.y = element_line(color = "grey90"),
            panel.grid.minor.y = element_line(color = "grey90"), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent", color = "transparent"),
            legend.position = "none", 
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.15, 0.05, 0.15, 0.05),"cm")),
    
    
    # Welfare expansion
    ggplot(filter(BIBU.Centre, !is.na(COMPULSORY_SCHOOLING_BI)), 
           aes(x = ROUND, 
               stratum = COMPULSORY_SCHOOLING_BI, 
               fill = as.factor(COMPULSORY_SCHOOLING_BI), 
               alluvium = MEMBERID)) +
      scale_fill_manual(values = brewer.pal(n = 9, name = "Greys")[c(6, 4)]) +
      geom_flow(width = 0.75) +
      geom_stratum(alpha = 0.5, width = 0.75) + 
      geom_text(stat = "stratum", color = "black", aes(label = percent(after_stat(prop), accuracy = .1)), size = 11/.pt, vjust = -0.1) +
      geom_text(stat = "stratum", color = "black", aes(label = paste0("(N=",after_stat(count),")")), size = 8.5/.pt, vjust = 1.1) +
      scale_x_discrete(limits = c("Round 1", "Round 2"), labels = c("Before\nthe reform", "After\nthe reform")) +
      labs(title = NULL, x = NULL, y = NULL) +
      coord_cartesian(xlim = c(0.6, 2.6), 
                      ylim = c(-(nrow(filter(BIBU.Centre, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*0.01, 
                               (nrow(filter(BIBU.Centre, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*1.01), 
                      expand = FALSE, 
                      clip = "off") +
      scale_y_continuous(breaks = seq(from = 0, 
                                      to = nrow(filter(BIBU.Centre, !is.na(COMPULSORY_SCHOOLING_BI)))/2, 
                                      by = nrow(filter(BIBU.Centre, !is.na(COMPULSORY_SCHOOLING_BI)))/10),
                         labels = c("0%", "20%", "40%", "60%", "80%", "100%")) +
      geom_rect(ymin = -(nrow(filter(BIBU.Centre, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*0.01, 
                ymax =  (nrow(filter(BIBU.Centre, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*1.01, 
                xmin = 2.4, 
                xmax = 2.6, 
                colour = "black", 
                fill = "grey90") +
      annotate("text", x = 2.5, y = (nrow(filter(BIBU.Centre, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*0.5, hjust = 0.5, vjust = 0.5, label = "Centre Party", angle = 270, fontface = 2, size = 13/.pt) +
      theme(text = element_text(size = 12, color = "black"),
            axis.text.x = element_blank(),
            panel.grid.major.x = element_blank(),
            panel.grid.minor.x = element_blank(), 
            panel.grid.major.y = element_line(color = "grey90"),
            panel.grid.minor.y = element_line(color = "grey90"), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent", color = "transparent"),
            legend.position = "none", 
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.15, 0.05, 0.15, 0.05),"cm")),
    
    # General specs
    ncol = 3, widths = c(3, 4, 4.25),
    align = "hv")





# _ Swedish People's Party ------------------------------------------------

# __ Data preparation -----------------------------------------------------
BIBU.SwedisPP <-
  BIBU.DiD %>%
  select(MEMBERID, ROUND, RETIREMENT_TUBE_BI, PartyChoice.Overall) %>%
  filter(PartyChoice.Overall == "Swedish Peoples Party") %>%
  na.omit() %>%
  group_by(MEMBERID) %>%
  mutate(count = n()) %>%
  filter(count == 2) %>%
  select(-count)

BIBU.SwedisPP <-
  BIBU.DiD %>%
  select(MEMBERID, ROUND, COMPULSORY_SCHOOLING_BI, PartyChoice.Overall) %>%
  filter(PartyChoice.Overall == "Swedish Peoples Party") %>%
  na.omit() %>%
  group_by(MEMBERID) %>%
  mutate(count = n()) %>%
  filter(count == 2) %>%
  select(-c(count, PartyChoice.Overall)) %>%
  full_join(., BIBU.SwedisPP, by = c("MEMBERID", "ROUND"))

BIBU.SwedisPP <-
  BIBU.DiD %>%
  select(MEMBERID, ROUND, LeftRight, PartyChoice.Overall) %>%
  filter(PartyChoice.Overall == "Swedish Peoples Party") %>%
  na.omit() %>%
  group_by(MEMBERID) %>%
  mutate(count = n()) %>%
  filter(count == 2) %>%
  select(-c(count, PartyChoice.Overall)) %>%
  full_join(., BIBU.SwedisPP, by = c("MEMBERID", "ROUND"))

BIBU.SwedisPP$PartyChoice.Overall <- "Swedish Peoples Party"




# __ Figure ---------------------------------------------------------------

SwedisPP <-
  ggarrange(
    # Kernel density plot
    ggplot(filter(BIBU.SwedisPP, !is.na(LeftRight) & ROUND == "Round 1"), 
           aes(x = LeftRight)) +
      geom_density(alpha = 0.65, 
                   bw = 0.75, 
                   color = brewer.pal(n = 9, name = "Greys")[5],
                   fill = brewer.pal(n = 9, name = "Greys")[3]) +
      geom_segment(x = mean(BIBU.SwedisPP$LeftRight), 
                   xend = mean(BIBU.SwedisPP$LeftRight), 
                   y = 0, 
                   yend = 0.212, 
                   color = brewer.pal(n = 9, name = "Greys")[7], 
                   linetype = "longdash") +
      scale_x_continuous(breaks = seq(0, 10, 1), labels = c("0", "\nLeft", "", "", "", "5", "", "", "", "\nRight", "10")) +
      scale_y_continuous(breaks = seq(0, 0.5, 0.05), labels = c("0.0", "", "0.1", "", "0.2", "", "0.3", "", "0.4", "", "0.5")) +
      labs(title = NULL, x = NULL, y = NULL, fill = NULL, color = NULL) +
      coord_cartesian(xlim = c(0 - 0.33, 10 + 0.33), ylim = c(0, 0.5 * 1.01), expand = FALSE, clip = "off") +
      theme(text = element_text(size = 12, color = "black"),
            panel.grid.major.x = element_blank(), 
            panel.grid.major.y = element_line(colour = "gray90"), 
            panel.grid.minor.y = element_blank(), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent"),
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.05, 0.2, 0.05, 0.05),"cm")),
    
    
    # Welfare retrenchment
    ggplot(filter(BIBU.SwedisPP, !is.na(RETIREMENT_TUBE_BI)), 
           aes(x = ROUND, 
               stratum = RETIREMENT_TUBE_BI, 
               fill = as.factor(RETIREMENT_TUBE_BI), 
               alluvium = MEMBERID)) +
      scale_fill_manual(values = brewer.pal(n = 9, name = "Greys")[c(6, 4)]) +
      geom_flow(width = 0.75) +
      geom_stratum(alpha = 0.5, width = 0.75) + 
      geom_text(stat = "stratum", color = "black", aes(label = percent(after_stat(prop), accuracy = .1)), size = 11/.pt, vjust = -0.1) +
      geom_text(stat = "stratum", color = "black", aes(label = paste0("(N=",after_stat(count),")")), size = 8.5/.pt, vjust = 1.1) +
      scale_x_discrete(limits = c("Round 1", "Round 2"), labels = c("Before\nthe reform", "After\nthe reform")) +
      labs(title = NULL, x = NULL, y = NULL) +
      coord_cartesian(xlim = c(0.6, 2.4), 
                      ylim = c(-(nrow(filter(BIBU.SwedisPP, !is.na(RETIREMENT_TUBE_BI)))/2)*0.01, 
                               (nrow(filter(BIBU.SwedisPP, !is.na(RETIREMENT_TUBE_BI)))/2)*1.01), 
                      expand = FALSE, 
                      clip = "off") +
      scale_y_continuous(breaks = seq(from = 0, 
                                      to = nrow(filter(BIBU.SwedisPP, !is.na(RETIREMENT_TUBE_BI)))/2, 
                                      by = nrow(filter(BIBU.SwedisPP, !is.na(RETIREMENT_TUBE_BI)))/10),
                         labels = c("0%", "20%", "40%", "60%", "80%", "100%")) +
      theme(text = element_text(size = 12, color = "black"),
            panel.grid.major.x = element_blank(),
            panel.grid.minor.x = element_blank(), 
            panel.grid.major.y = element_line(color = "grey90"),
            panel.grid.minor.y = element_line(color = "grey90"), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent", color = "transparent"),
            legend.position = "none", 
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.15, 0.05, 0.15, 0.05),"cm")),
    
    
    # Welfare expansion
    ggplot(filter(BIBU.SwedisPP, !is.na(COMPULSORY_SCHOOLING_BI)), 
           aes(x = ROUND, 
               stratum = COMPULSORY_SCHOOLING_BI, 
               fill = as.factor(COMPULSORY_SCHOOLING_BI), 
               alluvium = MEMBERID)) +
      scale_fill_manual(values = brewer.pal(n = 9, name = "Greys")[c(6, 4)]) +
      geom_flow(width = 0.75) +
      geom_stratum(alpha = 0.5, width = 0.75) + 
      geom_text(stat = "stratum", color = "black", aes(label = percent(after_stat(prop), accuracy = .1)), size = 11/.pt, vjust = -0.1) +
      geom_text(stat = "stratum", color = "black", aes(label = paste0("(N=",after_stat(count),")")), size = 8.5/.pt, vjust = 1.1) +
      scale_x_discrete(limits = c("Round 1", "Round 2"), labels = c("Before\nthe reform", "After\nthe reform")) +
      labs(title = NULL, x = NULL, y = NULL) +
      coord_cartesian(xlim = c(0.6, 2.6), 
                      ylim = c(-(nrow(filter(BIBU.SwedisPP, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*0.01, 
                               (nrow(filter(BIBU.SwedisPP, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*1.01), 
                      expand = FALSE, 
                      clip = "off") +
      scale_y_continuous(breaks = seq(from = 0, 
                                      to = nrow(filter(BIBU.SwedisPP, !is.na(COMPULSORY_SCHOOLING_BI)))/2, 
                                      by = nrow(filter(BIBU.SwedisPP, !is.na(COMPULSORY_SCHOOLING_BI)))/10),
                         labels = c("0%", "20%", "40%", "60%", "80%", "100%")) +
      geom_rect(ymin = -(nrow(filter(BIBU.SwedisPP, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*0.01, 
                ymax =  (nrow(filter(BIBU.SwedisPP, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*1.01, 
                xmin = 2.4, 
                xmax = 2.6, 
                colour = "black", 
                fill = "grey90") +
      annotate("text", x = 2.5, y = (nrow(filter(BIBU.SwedisPP, !is.na(COMPULSORY_SCHOOLING_BI)))/2)*0.5, hjust = 0.5, vjust = 0.5, label = "Swedish People's Party", angle = 270, fontface = 2, size = 13/.pt) +
      theme(text = element_text(size = 12, color = "black"),
            panel.grid.major.x = element_blank(),
            panel.grid.minor.x = element_blank(), 
            panel.grid.major.y = element_line(color = "grey90"),
            panel.grid.minor.y = element_line(color = "grey90"), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent", color = "transparent"),
            legend.position = "none", 
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.15, 0.05, 0.15, 0.05),"cm")),
    
    # General specs
    ncol = 3, widths = c(3, 4, 4.25),
    align = "hv")



# _ Combined figure -------------------------------------------------------
annotate_figure(
  ggarrange(SocialDemocrats,
            LeftAlliance,
            Greens,
            Centre,
            SwedisPP,
            nrow = 5, heights = c(6.25, 5, 5, 5, 5.5)),
  right = get_legend(ggplot(filter(BIBU.SwedisPP, !is.na(RETIREMENT_TUBE_BI)), 
                            aes(x = ROUND, 
                                stratum = RETIREMENT_TUBE_BI, 
                                fill = as.factor(RETIREMENT_TUBE_BI), 
                                alluvium = MEMBERID)) +
                       scale_fill_manual(values = brewer.pal(n = 9, name = "Greys")[c(6, 4)],
                                         labels = c("Strongly agree\nand agree", "Strongly disagree\nand disagree")) +
                       geom_flow(width = 0.75) +
                       geom_stratum(alpha = 0.5, width = 0.75) + 
                       guides(fill = guide_legend(byrow = TRUE)) +
                       labs(title = NULL, x = NULL, y = NULL, fill = NULL) +
                       theme(legend.spacing.y = unit(0.2, 'cm'),
                             legend.justification = c(0, 0.95))
                     )
  ) + theme(plot.background = element_rect(fill = "white", color = "white"))


# Saving the output
ggsave(filename = "02-figures and models/Fig 2 - government parties overview.png", width = 27, height = 32.5, units = "cm", dpi = 600)



# Cleanup
rm(BIBU.SocDem, BIBU.LeftA, BIBU.Greens, BIBU.Centre, BIBU.SwedisPP)
rm(SocialDemocrats, LeftAlliance, Greens, Centre, SwedisPP)
rm(BIBU.DiD)
